package br.com.werp.suporte.Usuario;

import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import com.egen.util.jdbc.*;
import com.egen.util.text.*;

/**
 * Creation Date 03/09/2004 10:09:18
 * Last Modify Date 03/09/2004 10:24:28
 */

public class GruposAction extends com.egen.util.struts.AbstractAction {

  public ActionForward perform_insert_action(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    ActionForward actionForward = null;
    com.egen.util.jdbc.JdbcUtil j = null;
    try {
      GruposActionForm f = (GruposActionForm) form;
      j = new com.egen.util.jdbc.JdbcUtil();
      insert_action(f, j, request);
      actionForward = mapping.findForward("same");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("ActionErrors.GLOBAL_ERROR", new ActionError("error.action.exception",(e)));
      request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
      session.setAttribute("exception", (e));
      actionForward = mapping.findForward("same");
    }
    finally { if (j != null) {
          j.close();
        }
            } return actionForward;
  }
  private void insert_action(GruposActionForm f, com.egen.util.jdbc.JdbcUtil j, HttpServletRequest request) throws Exception {
    HttpSession session = request.getSession(true);
    br.com.werp.suporte.dbobj.table.Grupos table = new br.com.werp.suporte.dbobj.table.Grupos();
    Object[][] name_value = { {"Grupos_nome",f.getGrupos_nome()}, };
    j.insert(table, name_value);
    session.setAttribute("GruposActionForm",new GruposActionForm());
    Vector res_Grupos = (Vector) session.getAttribute("res_Grupos");
    if (res_Grupos != null && table != null) {
      res_Grupos.addElement(table);
      session.setAttribute("res_Grupos", res_Grupos);
    }
  }

  public ActionForward perform_resetfull_action(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    ActionForward actionForward = null;
    GruposActionForm f = (GruposActionForm) form;
    try {
      session.removeAttribute("res_Grupos");
      session.removeAttribute("GruposActionForm");
      actionForward = mapping.findForward("same");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("ActionErrors.GLOBAL_ERROR", new ActionError("error.action.exception",(e)));
      request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
      session.setAttribute("exception", (e));
      actionForward = mapping.findForward("same");
    }
    return actionForward;
  }

}
